package com.yaoxiaowen.project2.test.annotations;

import android.support.annotation.IntDef;
import android.support.annotation.StringDef;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.widget.EditText;
import android.widget.TextView;

import com.yaoxiaowen.project2.R;
import com.yaoxiaowen.project2.base.BaseActivity;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import javax.xml.transform.Source;

import butterknife.BindView;
import butterknife.OnClick;


public class AnnotationsMainActivity extends BaseActivity {


    public static final int SUNDAY = 0;
    public static final int MONDAY = 1;
    public static final int TUESDAY = 2;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({SUNDAY, MONDAY, TUESDAY})
    public @interface WEEKDAY{};

    @WEEKDAY int today = SUNDAY;

    public static final String YAO_WEN = "yaoWen";
    public static final String LIU_FANG = "liuFang";
    public static final String HUANG_YUE = "huangYue";
    @Retention(RetentionPolicy.RUNTIME)
    @StringDef({YAO_WEN, LIU_FANG, HUANG_YUE})
    public @interface Name{};

    private @AnnotationsMainActivity.Name String studentName = "test";


    @BindView(R.id.annoEtInt)
    EditText annoEtInt;
    @BindView(R.id.annoEtString)
    EditText annoEtString;
    @BindView(R.id.annoDisplayIntTv)
    TextView annoDisplayIntTv;
    @BindView(R.id.annoDisplayStringTv)
    TextView annoDisplayStringTv;

    public static final String TAG = "AnnotationsMainActivity";
    private static final boolean DEBUG = true;
    private static final boolean IS_SHOW = true;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_annotations_main;
    }

    @Override
    protected void initData() {
        setDay(4);
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initListener() {

    }

    @OnClick(R.id.annoSaveIntBtn)
    public void saveIntOnClick(View view){
        setDay(getEtInt());
    }

    @OnClick(R.id.annoGetIntBtn)
    public void getIntOnClick(View view){
        annoDisplayIntTv.setText(" " + getDay());
    }


    @OnClick(R.id.annoSetStringBtn)
    public void setStringOnClick(View view){
        setName(getEtString());
    }

    @OnClick(R.id.annoGetStringBtn)
    public void getStringOnClick(View view){
        annoDisplayStringTv.setText(getName());
    }



    private void setDay(@WEEKDAY int day){
        today = day;
    }

    @WEEKDAY
    private int getDay(){
        return today;
    }

    private void setName(@Name String name){
        studentName = name;
    }

    @Name
    private String getName(){
        return studentName;
    }

    private int getEtInt(){
        String  string = annoEtInt.getText().toString().trim();
        mLog.i(DEBUG, TAG, "getEtInt() string=" + string);
        return Integer.parseInt(string);
    }

    private String getEtString(){
        String  string = annoEtString.getText().toString().trim();
        mLog.i(DEBUG, TAG, "getString() string=" + string);
        return string;
    }
}
